package com.lib76.socket.model.protocol;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SocketProtocolGroup {
	
	/**
	 * ��Ϣ������
	 */
	public final static String COMMAND_FIELD_NAME = "command";
	/**
	 * �������ʽ����
	 */
	public final static String BODY_TYPE_FIELD_NAME = "bodyType";
	/**
	 * 报文体长度
	 */
	public final static String BODY_LENGTH_FIELD_NAME = "bodyLength";
	/**
	 * ��Ϣ����request��response
	 */
	public final static String DIRECTION_FIELD_NAME = "type";
	/**
	 * ��Ϣ���ȣ�����ͷ����+�����峤�ȣ�
	 */
	public final static String MESSAGE_LENGTH_FIELD_NAME = "messageLength";

	private String version;
	private String type; //���ĸ�ʽ����
	
	private List<SocketProtocolParameter> headerParameters;
	
	private Map<String,SocketProtocol> protocols;
	
	public SocketProtocolGroup(){
		headerParameters = new ArrayList<SocketProtocolParameter>();
		protocols = new HashMap<String,SocketProtocol>();
	}
	
	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	/**
	 * ��ȡ���ĸ�ʽ���ͣ�byte��json��string
	 * @return
	 */
	public String getType() {
		return type;
	}

	/**
	 * ���ñ��ĸ�ʽ���ͣ�byte��json��string
	 * @param type
	 */
	public void setType(String type) {
		this.type = type;
	}
	
	public List<SocketProtocolParameter> getHeaderParameters() {
		return headerParameters;
	}

	public void setHeaderParameters(List<SocketProtocolParameter> headerParameters) {
		this.headerParameters = headerParameters;
	}

	public Map<String, SocketProtocol> getProtocols() {
		return protocols;
	}

	public void setProtocols(Map<String, SocketProtocol> protocols) {
		this.protocols = protocols;
	}
	
	public int getHeaderLength(){
		int length = 0;
		for(SocketProtocolParameter parameter : headerParameters){
			if(parameter.getLength() != null){
				length = length + parameter.getLength();
			}
		}
		return length;
	}
}
